package vacuum.lgadmin.punishment;

import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerChatEvent;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.player.PlayerLoginEvent;

public class PunishmentPlayerListener implements Listener
{
	
	PunishmentPlugin pp;
	
	public PunishmentPlayerListener(PunishmentPlugin pp){
		this.pp = pp;
	}

	@EventHandler(priority=EventPriority.NORMAL)
	public void onPlayerChat(PlayerChatEvent event)
	{
		if(PunishmentPlugin.index(pp.muted, event.getPlayer().getName()) != -1){
			event.setCancelled(true);
			event.getPlayer().sendMessage("You are muted and cannot speak!");
		}
	}

	@EventHandler(priority=EventPriority.NORMAL)
	public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event)
	{
		if(PunishmentPlugin.index(pp.muted, event.getPlayer().getName()) != -1 && pp.commands.contains(event.getMessage().substring(1).toLowerCase())){
			event.setCancelled(true);
			event.getPlayer().sendMessage("You are muted and cannot use this command!");
		}
	}

	@EventHandler(priority=EventPriority.NORMAL)
	public void onPlayerLogin(PlayerLoginEvent event)
	{
		if(PunishmentPlugin.index(pp.banned, event.getPlayer().getName()) != -1){
			event.getPlayer().kickPlayer("You were banned from the server!");
		}
	}

}
